<script type="text/javascript">
$(function(){
	var pg = App.base.sysParamIndex.ui
		, infoPl = pg.children('.infoPl')
		, hd = infoPl.children('.head')
		, bd = infoPl.children('.body')
		, gd = bd.find('.grid')
		, ttLb = hd.seek('title');

	gd.mac('grid', {
		rowHeight: 30,
		footerHeight: 32,
		cols : [{
			field: 'catalog', title : '分组', width: 80, sort: true
		},{
			field: 'code', title : '参数名', width: 250, sort: true, render: function(r){
				return $('<a href="#">' + r.code + '</a>').click(function(){
					App.open({
						ctx:'base',
						action: 'sysParamEdit',
						params: r,
						model : true
					}, gd.load);
				});
			}
		},{
			field: 'value', title : '值', width: 200, sort: true
		},{
			field: 'status', title : '状态', width: 80, sort: true,
			render: function(r, tr, me){
				return r.status? '已启用':'已停用';
			}
		},{
			field: 'memo', title : '备注', width: 200
		},{
			name: 'action', field: 'status', title: '操作', width: 120,
			render: function(r, tr, me){
				var a = $('<div></div>');
				if (App.logon.power('param.status')) {
					$('<span class="a"></span>').click(function(){
						var el = $(this);
						mac.confirm(Msg.confirm.message, function(){
							var w = mac.wait(Msg.info.waiting, [ el.html() ]);
							$.post(App.ctx + '/param/' + (r.status? 'stop':'start') + '.do', {
								id: r.id
							}, function(rs){
								var ro = mac.eval(rs);
								if (ro.success){
									me.load();
								} else {
									App.error(el.html(), ro.data);
								}
								w.close();
							});
						}, [ el.html() ]);
					}).append(r.status? '停用':'启用').appendTo(a);
					a.append('&nbsp;');
				}
				if (App.logon.power('param.delete')) {
					$('<span class="a"></span>').click(function(){
						var el = $(this);
						mac.confirm(Msg.confirm.message, function(){
							var w = mac.wait(Msg.info.waiting, [ el.html() ]);
							$.post(App.ctx + '/param/delete.do', {
								id: r.id
							}, function(rs){
								var ro = mac.eval(rs);
								if(ro.success){
									me.load();
								} else {
									App.error(el.html(), ro.data);
								} 
								w.close();
							});
						}, [ el.html() ]).appendTo(a);
					}).append('删除').appendTo(a);
				}
				return a;
			}
		}],
		loader: {
			url: App.ctx + '/param/list.do',
			params: { pageNo: 1, pageSize: 10, 'spp': '', key: '' },
			autoLoad: true
		},
		pagerLength: 10,
		onLoadFailed: function(dd) {
			App.error('读取环境列表', dd);
		}
	});
	pg.find('.toolbar .item').click(function(){
		var el = $(this), act = el.attr('name');
		switch(act){
		case 'add':
			App.open({
				action: '',
				model : true
			}, gd.load);
			break;
		}
	});
	pg.seek('query').click(function(){
		gd.load({ key: pg.seek('key').val()});
	});
	
	if (App.logon.power('param.add')) {
		hd.seek('add').click(function(){
			App.open({
				ctx:'base',
				action: 'sysParamEdit',
				modal: true,
				params: {
				}
			}, function(){
				//重新加载列表
				gd.load();
			})
		}).show();
	}
	
	pg.seek('back').click(function(){
		ttLb.text('主页');
		App.show({
			title: '主页',
			ctx: 'deploy',
			action: 'home',
			params: {}
		}, $.noop, pg.parent());
	});
	
	function adjust(){
		var h = pg.parent().height(),w=pg.parent().width();
		h -=16;
		infoPl.height(h);
		infoPl.width(w-16);
		h -= pg.children('.head').height();
		h -= pg.children('.navi').height();
		bd.height(h)
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
	
	pg.find('[placeholder]').mac('placeholder');
});
</script>
<div class="infoPl">
	<div class="navi">
		<span class="a" name="back">主页</span>&gt;&gt; <span class="a"
			name="title">系统参数管理</span>
	</div>
	<div class="head">
		<button name="add" class="hidden">添加新参数</button>
		<input name="key" type="text" placeholder="请输入参数名" />
		<button name="query">查找</button>
	</div>
	<div class="body">
		<div class="grid"></div>
	</div>
</div>
